package com.online.studyonline.controller;


import com.online.studyonline.pojo.Note;
import com.online.studyonline.pojo.Result;
import com.online.studyonline.pojo.ResultT;
import com.online.studyonline.service.NoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/note")
public class NoteController {
    @Autowired
    private NoteService noteService;

    @GetMapping("/getNote")
    public ResultT<List<Note>> getByUserId(Integer id){

        return noteService.getNoteByUserId(id);
    }
    @GetMapping("/getNoteAndCourse")
    public ResultT<List<Note>> getByUserId1(Integer id){
        return noteService.getNoteByUserId1(id);
    }



    @PostMapping("/addNote2")
    public ResultT<String> addNote(String courseName, Integer userId, String noteText){
        return noteService.addNote(courseName,userId,noteText);
    }

    @DeleteMapping("/delNote")
    public ResultT<String> delNote(Integer noteId){
        return noteService.delNote(noteId);
    }

    @GetMapping("/getAll")
    public ResultT<List<Note>> getAll(){
        List<Note> list = noteService.getAll();
        return ResultT.success(list);
    }


    @GetMapping("/getNoteList")
    public Result getNoteList(@RequestParam("videoId") Integer videoId, @RequestParam("userId") Integer userId){
        List<Note> noteList = noteService.lambdaQuery().eq(Note::getVideoId, videoId).eq(Note::getUserId, userId).list();
        return Result.success(noteList);
    }
    @PostMapping("/addNote")
    public Result addNote(@RequestBody Note note){
//        System.out.println(note.getNoteText());
        return Result.success(noteService.save(note));
    }
}
